package com.ruoyi.account.enums;

import cn.hutool.core.util.StrUtil;
import com.ruoyi.laiqianba.enums.AccountTypeEnum;
import lombok.Getter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 操作类型枚举
 * */
@Getter
public enum ActionTypeEnum {

    CZ("CZ", "充值")
    ,TK("TK", "退款")

    ,BD("BD", "补单")
    ,BK("BK", "补扣")

    ,CHANNEL_PAYOUT("CHANNEL_PAYOUT", "采量支出")
    ,COMPANY_PAYOUT("COMPANY_PAYOUT", "公司运营")
    ,STAFF_SALARY("STAFF_SALARY", "员工工资")
    ,STAFF_PERCENT("STAFF_PERCENT", "员工提成")
    ,AGENT_REBATE("AGENT_REBATE", "代理返点")

    ,XH("XH", "消耗")

    ,TZ("TZ", "调账")
    ,INCOME("INCOME", "收入")

    ;

    static List<ActionTypeEnum> merchantTypeList = new ArrayList<>();
    static List<ActionTypeEnum> productTypeList = new ArrayList<>();
    static List<ActionTypeEnum> accountTypeList = new ArrayList<>();// 总账
    static {
        // 商户机构
        merchantTypeList.add(CZ);
        merchantTypeList.add(TK);
        merchantTypeList.add(BD);
        merchantTypeList.add(BK);

        productTypeList.add(CZ);
        productTypeList.add(TK);
        productTypeList.add(BD);
        productTypeList.add(BK);

        accountTypeList.add(INCOME);
        accountTypeList.add(TZ);
        accountTypeList.add(TK);
        accountTypeList.add(CHANNEL_PAYOUT);
        accountTypeList.add(COMPANY_PAYOUT);
        accountTypeList.add(STAFF_SALARY);
        accountTypeList.add(STAFF_PERCENT);
        accountTypeList.add(AGENT_REBATE);

    }

    private String value;
    private String name;

    public static List<Map<String, String>> getActionTypeMapList(){
        List<Map<String, String>> resultList = new ArrayList<>();
        for (ActionTypeEnum actionTypeEnum : values()) {
            Map<String, String> itemMap = new HashMap<>();
            itemMap.put("key", actionTypeEnum.getName());
            itemMap.put("value", String.valueOf(actionTypeEnum.getValue()));
            resultList.add(itemMap);
        }
        return resultList;
    }

    ActionTypeEnum(String value, String name){
        this.value = value;
        this.name = name;
    }

    public static ActionTypeEnum getEntityByType(String actionType){
        for (ActionTypeEnum typeEnum : values()) {
            if (StrUtil.equals(typeEnum.getValue(), actionType)){
                return typeEnum;
            }
        }
        return null;
    }

    //通过value拿到name值
    public static String getNameByValue(String value){
        for (ActionTypeEnum typeEnum : values()) {
            if (StrUtil.equals(typeEnum.getValue(), value)){
                return typeEnum.getName();
            }
        }
        return null;
    }

    public static List<Map<String, String>> getActionTypeMapListByAccount(String accountType){

        List<ActionTypeEnum> typeList = new ArrayList<>();
        if (StrUtil.equals(accountType, AccountTypeEnum.ACCOUNT.getValue())){
            typeList = accountTypeList;
        }else if (StrUtil.equals(accountType, AccountTypeEnum.MERCHANT.getValue())){
            typeList = merchantTypeList;
        }else if (StrUtil.equals(accountType, AccountTypeEnum.PRODUCT.getValue())){
            typeList = productTypeList;
        }

        List<Map<String, String>> resultList = new ArrayList<>();

        for (ActionTypeEnum actionTypeEnum : typeList) {
            Map<String, String> itemMap = new HashMap<>();
            itemMap.put("name", actionTypeEnum.getName());
            itemMap.put("value", actionTypeEnum.getValue());
            resultList.add(itemMap);
        }
        return resultList;
    }
}
